<?php
namespace app\branch\controller;

use think\Controller;
use think\Session;
use think\Request;

/**
 * 分公司会员管理
 */
class Usercontrol extends Controller
{   
    use \app\common\traits\controller\TraitController;
    //登陆判断
    protected $beforeActionList = [
        'checkLogin',
    ];
    protected function checkLogin()
    {
        if (!model('Managers')->checkLogin()) {
            $this->redirect('@manager/login');
            exit;
        }
    }
    /**
     * [getList 会员管理列表]
     * @return [type] [description]
     */
    public function getList()
    {
      //去本公司下的营地
      $lo_bran_id = model('Managers')->getLoginUserInfo('branch_id');
      $campinfos = model('Campcontrols')->where('branch_id',$lo_bran_id)->select();
      $this->assign('campinfos',$campinfos);
      //取本公司下的会员
      $campid = model('Campcontrols')->where('branch_id',$lo_bran_id)->column('id');
      if (empty($campid)) {
        return $this->error(lang('no camp information, so no member information'),$url = null,'',$wait=5);
      }
      $query = ['camp_id'=>['in',$campid]];
      $list = model('Usercontrols')->getUserList(array_merge(input('get.'),$query));
      return view('usercontrol/list',['list'=>$list]);
    }
     /**
     * [getReadInfo 查看会员信息]
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function getReadInfo($id)
    {
        //会员信息
        $userinfo = model("Usercontrols")->getUserIofo($id);
        //会员联系人信息
        $con_info = db('contactioninfo')->where('user_id',$id)->select();
        $user_car_name = db('caravan')->where('user_id',$id)->value('name');
        $this->assign('user_car_name',$user_car_name);
        return view('usercontrol/userinfo',['userinfo'=>$userinfo,'con_info'=>$con_info]);
    }
}
